<?php
namespace app\admin\controller;
use think\Db;
use lib\Curl;
class Reason extends Base{
    public function ciya_reason_title(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('ciya_reason_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $res=Db::name('ciya_reason_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function ciya_reason(){
        $list=Db::name('ciya_reason')->order('id desc')->paginate(10);
        $counts=Db::name('ciya_reason')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function ciya_reason_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res= Db::name('ciya_reason')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function ciya_reason_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('ciya_reason')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['icon']=$param['icon'];
            $data['sort']=$param['sort'];
            $res=Db::name('ciya_reason')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function ciya_reason_del(){
        $param = input('post.');
        $res= Db::name('ciya_reason')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
}